package com.ysz.component.encrypt.strategy;

import com.ysz.component.encrypt.IEncryptResultCodeStrategy;
import org.apache.commons.lang3.CharSet;
import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @ClassName EncryptionResultCodeStrategy
 * @Description TODO
 * @Data 14:44
 * @Version 1.0
 * @Author ysz
 */
public class EncryptionResultCodeStrategy implements IEncryptResultCodeStrategy {

    @Override
    public String encryption(String originalValue) {
        if (StringUtils.isNotEmpty(originalValue)) {
            try {
                MessageDigest messageDigest = MessageDigest.getInstance("MD5");
                byte[] digest = messageDigest.digest(originalValue.getBytes(StandardCharsets.UTF_8));
                return new BigInteger(1, digest).toString(16);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
